var webpack = require('webpack')
const fs = require('fs')
require('events').EventEmitter.defaultMaxListeners = 0;

const proxyMap = {
  hq: 'http://121.40.210.64:60001/',
  prod: 'http://47.96.25.44:60001/',
  rd: 'http://211.71.220.3/',
  zky: 'http://114.251.170.156:60001/',
  test: 'https://192.168.2.112:8242/',
  dev: 'http://192.168.2.242:60001/',
  dev3: 'http://192.168.2.233:8281/',
  ytj: 'http://192.168.2.178:8281/',
  wnyxy: 'http://218.22.81.119:8281/'
}

const proxyTarget = 'http://xxx'

const proxyRouter = () => {
  return fs.readFileSync(process.cwd() + '/target.env', 'utf8')
}

module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? '/ilink-bs/' : '/',
  assetsDir: 'static',
  outputDir: 'dist/ilink-bs',
  productionSourceMap: false,
  devServer: {
    disableHostCheck: true,
    hot: true,
    port: 2020,
    host: '0.0.0.0',
    https: false,
    open: true,
    proxy: {
      '/bs': {
        target: proxyTarget,
        secure: false,
        changeOrigin: true,
        router: proxyRouter
      },
      '/websocket': {
        target: proxyTarget,
        ws: true,
        secure: false,
        changeOrigin: true,
        router: proxyRouter
      },
      '/ilink-fe-config': {
        target: proxyTarget,
        secure: false,
        changeOrigin: true,
        router: proxyRouter
      },
      '/staticRes': {
        target: proxyTarget,
        secure: false,
        changeOrigin: true,
        router: proxyRouter
      },
      '/ilink-file': {
        target: proxyTarget,
        secure: false,
        changeOrigin: true,
        router: proxyRouter
      },
      '/baiduapi': {
        target: 'http://api.map.baidu.com',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '/baiduapi/': '/'
        }
      },
      // 高新区报警短信
      '/sms': {
        target: 'http://192.168.2.88:15000',
        secure: false,
        changeOrigin: true
      },
      '/websocketGXQ': {
        target: 'http://192.168.2.88:15002',
        ws: true,
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '/websocketGXQ/': '/'
        }
      },
    }
  },
  configureWebpack: {
    devtool: 'source-map',
    plugins: [
      new webpack.ProvidePlugin({
        jQuery: 'jquery',
        $: 'jquery',
        'window.jQuery': 'jquery'
      })
    ],
    externals: {
      BMap: 'BMap',
      BMapLib: 'BMapLib'
    }
  }
}
